//
//  HPChildren.m
//
//  Created by 啊  on 16/4/24
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "HPChildren.h"


NSString *const kHPChildrenPId = @"pId";
NSString *const kHPChildrenCId = @"cId";
NSString *const kHPChildrenCSex = @"cSex";
NSString *const kHPChildrenCreateTime = @"createTime";
NSString *const kHPChildrenCName = @"cName";
NSString *const kHPChildrenCBirthday = @"cBirthday";


@interface HPChildren ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation HPChildren

@synthesize pId = _pId;
@synthesize cId = _cId;
@synthesize cSex = _cSex;
@synthesize createTime = _createTime;
@synthesize cName = _cName;
@synthesize cBirthday = _cBirthday;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.pId = [self objectOrNilForKey:kHPChildrenPId fromDictionary:dict];
            self.cId = [[self objectOrNilForKey:kHPChildrenCId fromDictionary:dict] doubleValue];
            self.cSex = [[self objectOrNilForKey:kHPChildrenCSex fromDictionary:dict] doubleValue];
            self.createTime = [self objectOrNilForKey:kHPChildrenCreateTime fromDictionary:dict];
            self.cName = [self objectOrNilForKey:kHPChildrenCName fromDictionary:dict];
            self.cBirthday = [self objectOrNilForKey:kHPChildrenCBirthday fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.pId forKey:kHPChildrenPId];
    [mutableDict setValue:[NSNumber numberWithDouble:self.cId] forKey:kHPChildrenCId];
    [mutableDict setValue:[NSNumber numberWithDouble:self.cSex] forKey:kHPChildrenCSex];
    [mutableDict setValue:self.createTime forKey:kHPChildrenCreateTime];
    [mutableDict setValue:self.cName forKey:kHPChildrenCName];
    [mutableDict setValue:self.cBirthday forKey:kHPChildrenCBirthday];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.pId = [aDecoder decodeObjectForKey:kHPChildrenPId];
    self.cId = [aDecoder decodeDoubleForKey:kHPChildrenCId];
    self.cSex = [aDecoder decodeDoubleForKey:kHPChildrenCSex];
    self.createTime = [aDecoder decodeObjectForKey:kHPChildrenCreateTime];
    self.cName = [aDecoder decodeObjectForKey:kHPChildrenCName];
    self.cBirthday = [aDecoder decodeObjectForKey:kHPChildrenCBirthday];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_pId forKey:kHPChildrenPId];
    [aCoder encodeDouble:_cId forKey:kHPChildrenCId];
    [aCoder encodeDouble:_cSex forKey:kHPChildrenCSex];
    [aCoder encodeObject:_createTime forKey:kHPChildrenCreateTime];
    [aCoder encodeObject:_cName forKey:kHPChildrenCName];
    [aCoder encodeObject:_cBirthday forKey:kHPChildrenCBirthday];
}

- (id)copyWithZone:(NSZone *)zone
{
    HPChildren *copy = [[HPChildren alloc] init];
    
    if (copy) {

        copy.pId = [self.pId copyWithZone:zone];
        copy.cId = self.cId;
        copy.cSex = self.cSex;
        copy.createTime = [self.createTime copyWithZone:zone];
        copy.cName = [self.cName copyWithZone:zone];
        copy.cBirthday = [self.cBirthday copyWithZone:zone];
    }
    
    return copy;
}


@end
